<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <title th:text="${session.title}">123</title>
    <link th:replace="common/header" />
    <link rel="stylesheet" th:href="@{/css/ace-skins.min.css}" />
    <script type="text/javascript">
        function sub(){
            var pwd = $("#password").val();
            var newpwd = $("#newpwd").val();
            var newpwd2 = $("#newpwd2").val();
            var pe = $("#passworderror");
            pe.html("");
            var ne = $("#newpwderror");
            ne.html("");
            var ne2 = $("#newpwd2error");
            ne2.html("");
            if(pwd === ''){
                pe.html("原密码不能为空");
                return;
            }
            if(newpwd === ''){
                ne.html("新密码不能为空");
                return;
            }
            if(newpwd2 === ''){
                ne2.html("确认密码不能为空");
                return;
            }
            if(newpwd !== newpwd2){
                ne2.html("两次输入新密码不同，请检查");
                return;
            }
            $.ajax({
                type: "POST",
                dataType: "text",
                url: "/changepwd",
                data: "password=" + pwd + "&newpwd=" + newpwd,
                success: function(data){
                    if(data === 'relogin'){
                        window.location.href="/logout";
                    }else if(data === "ok"){
                        showTip('tip','修改密码成功',4000);
                        $("#password").val("");
                        $("#newpwd").val("");
                        $("#newpwd2").val("");
                    }else if(data === 'length'){
                        $("#newpwderror").html("新密码太长");
                    }else{
                        showTip('tip','修改密码失败',4000);
                    }
                }
            });
        }
    </script>
</head>
<body class="navbar-fixed">
<div th:replace="common/top"></div>
<div class="container-fluid main_bg" id="main-container">
    <a id="menu-toggler" href="#"><span></span></a>
    <div th:replace="common/menu"></div>
    <div id="main-content" class="clearfix">
        <div id="page-content" class="clearfix">
            <div th:replace="common/title"></div>
            <div class="row-fluid">
                <!--page-content-->
                <div class="span12">
                    <div class="login-container">
                        <div class="space-6"></div>
                        <div class="row-fluid">
                            <div class="position-relative">
                                <div id="signup-box" class="visible widget-box no-border">
                                    <div class="widget-body">
                                        <div class="widget-main">
                                            <h4 class="header green lighter bigger"> <em class="icon-group green"></em>个人中心</h4>
                                            <div class="space-6"></div>
                                            <p style="color: #ccc; ">修改密码</p>
                                            <fieldset>
                                                <label> <span class="block input-icon input-icon-right"> <input id="password" class="span12" type="password" placeholder="原密码" /> <em class="icon-lock"></em> </span> <span><span id="passworderror" style="color:red"></span></span> </label>
                                                <label> <span class="block input-icon input-icon-right"> <input id="newpwd" class="span12" type="password" placeholder="新密码" /> <em class="icon-lock"></em> </span> <span><span id="newpwderror" style="color:red"></span></span> </label>
                                                <label> <span class="block input-icon input-icon-right"> <input id="newpwd2" class="span12" type="password" placeholder="确认密码" /> <em class="icon-lock"></em> </span> <span><span id="newpwd2error" style="color:red"></span></span> </label>
                                                <div class="row-fluid">
                                                    <label class="span3"></label>
                                                    <button type="button" onclick="return sub();" class="span6 btn btn-small btn-success"> <em class="icon-lightbulb"></em> 修改密码 </button>
                                                </div>
                                            </fieldset>
                                        </div>
                                        <!--/widget-main-->
                                        <div class="toolbar center">
                                            <a th:href="@{/index}" class="back-to-login-link"> <em class="icon-arrow-left"></em> 返回首页 </a>
                                        </div>
                                    </div>
                                    <!--/widget-body-->
                                </div>
                                <!--/forgot-box-->
                                <!--/signup-box-->
                            </div>
                            <!--/position-relative-->
                        </div>
                    </div>
                </div>
                <!--/span-->
                <!--/#page-content-->
            </div>
        </div>
        <div th:replace="common/skin :: skin"></div>
    </div>
    <!--/#main-content-->
</div>
<!--/.fluid-container#main-container-->
<div th:replace="common/js"></div>
</body>
</html>